<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html lang = "en">

<head>

<link rel="shortcut icon" href="http://algs4.cs.princeton.edu/favicon.ico">
<link rel="stylesheet"    href="http://algs4.cs.princeton.edu/java.css" type="text/css">

<title>BinomialMinPQ.java</title>

<meta HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<meta NAME="AUTHOR" CONTENT="Robert Sedgewick and Kevin Wayne">
<meta NAME="DESCRIPTION" CONTENT="BinomialMinPQ code in Java">
<meta NAME="TITLE" CONTENT="BinomialMinPQ code in Java">
<meta NAME="KEYWORDS" CONTENT="BinomialMinPQ,java,programming,computer science,algorithm,data structure,program,code">
<meta NAME="ROBOTS" CONTENT="INDEX,FOLLOW">

</head>


<body>
<center><h1>BinomialMinPQ.java</h1></center><p><br>

Below is the syntax highlighted version of <a href = "BinomialMinPQ.java">BinomialMinPQ.java</a>.
<p><br>

<!-- Generator: GNU source-highlight 3.1.6
by Lorenzo Bettini
http://www.lorenzobettini.it
http://www.gnu.org/software/src-highlite -->
<pre><tt><span class="comment">/******************************************************************************</span>
<span class="comment"> *  Compilation: javac BinomialMinPQ.java</span>
<span class="comment"> *  Execution:</span>
<span class="comment"> *  </span>
<span class="comment"> *  A binomial heap.</span>
<span class="comment"> *  </span>
<span class="comment"> ******************************************************************************/</span>

<span class="preproc">package</span><span class="normal"> edu</span><span class="symbol">.</span><span class="normal">princeton</span><span class="symbol">.</span><span class="normal">cs</span><span class="symbol">.</span><span class="normal">algs4</span><span class="symbol">;</span>

<span class="preproc">import</span><span class="normal"> java</span><span class="symbol">.</span><span class="normal">util</span><span class="symbol">.</span><span class="normal">Iterator</span><span class="symbol">;</span>
<span class="preproc">import</span><span class="normal"> java</span><span class="symbol">.</span><span class="normal">util</span><span class="symbol">.</span><span class="normal">Comparator</span><span class="symbol">;</span>
<span class="preproc">import</span><span class="normal"> java</span><span class="symbol">.</span><span class="normal">util</span><span class="symbol">.</span><span class="normal">NoSuchElementException</span><span class="symbol">;</span>

<span class="comment">/**</span>
<span class="comment"> *  The BinomialMinPQ class represents a priority queue of generic keys.</span>
<span class="comment"> *  It supports the usual insert and delete-the-minimum operations, </span>
<span class="comment"> *  along with the merging of two heaps together.</span>
<span class="comment"> *  It also supports methods for peeking at the minimum key,</span>
<span class="comment"> *  testing if the priority queue is empty, and iterating through</span>
<span class="comment"> *  the keys.</span>
<span class="comment"> *  It is possible to build the priority queue using a Comparator.</span>
<span class="comment"> *  If not, the natural order relation between the keys will be used.</span>
<span class="comment"> *  </span>
<span class="comment"> *  This implementation uses a binomial heap.</span>
<span class="comment"> *  The insert, delete-the-minimum, union, min-key</span>
<span class="comment"> *  and size operations take logarithmic time.</span>
<span class="comment"> *  The is-empty and constructor operations take constant time.</span>
<span class="comment"> * </span>
<span class="comment"> *  </span><span class="type">@author</span><span class="comment"> Tristan Claverie</span>
<span class="comment"> */</span>
<span class="keyword">public</span><span class="normal"> </span><span class="keyword">class</span><span class="normal"> </span><span class="classname">BinomialMinPQ</span><span class="symbol">&lt;</span><span class="normal">Key</span><span class="symbol">&gt;</span><span class="normal"> </span><span class="keyword">implements</span><span class="normal"> Iterable</span><span class="symbol">&lt;</span><span class="normal">Key</span><span class="symbol">&gt;</span><span class="normal"> </span><span class="cbracket">{</span>
<span class="normal">	</span><span class="keyword">private</span><span class="normal"> </span><span class="usertype">Node</span><span class="normal"> head</span><span class="symbol">;</span><span class="normal">    				</span><span class="comment">//head of the list of roots</span>
<span class="normal">	</span><span class="keyword">private</span><span class="normal"> </span><span class="keyword">final</span><span class="normal"> </span><span class="usertype">Comparator&lt;Key&gt;</span><span class="normal"> comp</span><span class="symbol">;</span><span class="normal">	</span><span class="comment">//Comparator over the keys</span>
<span class="normal">	</span>
<span class="normal">	</span><span class="comment">//Represents a Node of a Binomial Tree</span>
<span class="normal">	</span><span class="keyword">private</span><span class="normal"> </span><span class="keyword">class</span><span class="normal"> </span><span class="classname">Node</span><span class="normal"> </span><span class="cbracket">{</span>
<span class="normal">		</span><span class="usertype">Key</span><span class="normal"> key</span><span class="symbol">;</span><span class="normal">						</span><span class="comment">//Key contained by the Node</span>
<span class="normal">		</span><span class="type">int</span><span class="normal"> order</span><span class="symbol">;</span><span class="normal">						</span><span class="comment">//The order of the Binomial Tree rooted by this Node</span>
<span class="normal">		</span><span class="usertype">Node</span><span class="normal"> child</span><span class="symbol">,</span><span class="normal"> sibling</span><span class="symbol">;</span><span class="normal">			</span><span class="comment">//child and sibling of this Node</span>
<span class="normal">	</span><span class="cbracket">}</span>
<span class="normal">	</span>
<span class="normal">	</span><span class="comment">/**</span>
<span class="comment">	 * Initializes an empty priority queue</span>
<span class="comment">	 * Worst case is O(1)</span>
<span class="comment">	 */</span>
<span class="normal">	</span><span class="keyword">public</span><span class="normal"> </span><span class="function">BinomialMinPQ</span><span class="symbol">()</span><span class="normal"> </span><span class="cbracket">{</span>
<span class="normal">		comp </span><span class="symbol">=</span><span class="normal"> </span><span class="keyword">new</span><span class="normal"> </span><span class="function">MyComparator</span><span class="symbol">();</span>
<span class="normal">	</span><span class="cbracket">}</span>
<span class="normal">	</span>
<span class="normal">	</span><span class="comment">/**</span>
<span class="comment">	 * Initializes an empty priority queue using the given Comparator</span>
<span class="comment">	 * Worst case is O(1)</span>
<span class="comment">	 * </span><span class="type">@param</span><span class="comment"> C a comparator over the keys</span>
<span class="comment">	 */</span>
<span class="normal">	</span><span class="keyword">public</span><span class="normal"> </span><span class="function">BinomialMinPQ</span><span class="symbol">(</span><span class="usertype">Comparator&lt;Key&gt;</span><span class="normal"> C</span><span class="symbol">)</span><span class="normal"> </span><span class="cbracket">{</span>
<span class="normal">		comp </span><span class="symbol">=</span><span class="normal"> C</span><span class="symbol">;</span>
<span class="normal">	</span><span class="cbracket">}</span>
<span class="normal">	</span>
<span class="normal">	</span><span class="comment">/**</span>
<span class="comment">	 * Initializes a priority queue with given keys</span>
<span class="comment">	 * Worst case is O(n*log(n))</span>
<span class="comment">	 * </span><span class="type">@param</span><span class="comment"> a an array of keys</span>
<span class="comment">	 */</span>
<span class="normal">	</span><span class="keyword">public</span><span class="normal"> </span><span class="function">BinomialMinPQ</span><span class="symbol">(</span><span class="normal">Key</span><span class="symbol">[]</span><span class="normal"> a</span><span class="symbol">)</span><span class="normal"> </span><span class="cbracket">{</span>
<span class="normal">		comp </span><span class="symbol">=</span><span class="normal"> </span><span class="keyword">new</span><span class="normal"> </span><span class="function">MyComparator</span><span class="symbol">();</span>
<span class="normal">		</span><span class="keyword">for</span><span class="normal"> </span><span class="symbol">(</span><span class="usertype">Key</span><span class="normal"> k </span><span class="symbol">:</span><span class="normal"> a</span><span class="symbol">)</span><span class="normal"> </span><span class="function">insert</span><span class="symbol">(</span><span class="normal">k</span><span class="symbol">);</span>
<span class="normal">	</span><span class="cbracket">}</span>
<span class="normal">	</span>
<span class="normal">	</span><span class="comment">/**</span>
<span class="comment">	 * Initializes a priority queue with given keys using the given Comparator</span>
<span class="comment">	 * Worst case is O(n*log(n))</span>
<span class="comment">	 * </span><span class="type">@param</span><span class="comment"> C a comparator over the keys</span>
<span class="comment">	 * </span><span class="type">@param</span><span class="comment"> a an array of keys</span>
<span class="comment">	 */</span>
<span class="normal">	</span><span class="keyword">public</span><span class="normal"> </span><span class="function">BinomialMinPQ</span><span class="symbol">(</span><span class="usertype">Comparator&lt;Key&gt;</span><span class="normal"> C</span><span class="symbol">,</span><span class="normal"> Key</span><span class="symbol">[]</span><span class="normal"> a</span><span class="symbol">)</span><span class="normal"> </span><span class="cbracket">{</span>
<span class="normal">		comp </span><span class="symbol">=</span><span class="normal"> C</span><span class="symbol">;</span>
<span class="normal">		</span><span class="keyword">for</span><span class="normal"> </span><span class="symbol">(</span><span class="usertype">Key</span><span class="normal"> k </span><span class="symbol">:</span><span class="normal"> a</span><span class="symbol">)</span><span class="normal"> </span><span class="function">insert</span><span class="symbol">(</span><span class="normal">k</span><span class="symbol">);</span>
<span class="normal">	</span><span class="cbracket">}</span>

<span class="normal">	</span><span class="comment">/**</span>
<span class="comment">	 * Whether the priority queue is empty</span>
<span class="comment">	 * Worst case is O(1)</span>
<span class="comment">	 * </span><span class="type">@return</span><span class="comment"> true if the priority queue is empty, false if not</span>
<span class="comment">	 */</span>
<span class="normal">	</span><span class="keyword">public</span><span class="normal"> </span><span class="type">boolean</span><span class="normal"> </span><span class="function">isEmpty</span><span class="symbol">()</span><span class="normal"> </span><span class="cbracket">{</span>
<span class="normal">		</span><span class="keyword">return</span><span class="normal"> head </span><span class="symbol">==</span><span class="normal"> </span><span class="keyword">null</span><span class="symbol">;</span>
<span class="normal">	</span><span class="cbracket">}</span>

<span class="normal">	</span><span class="comment">/**</span>
<span class="comment">	 * Number of elements currently on the priority queue</span>
<span class="comment">	 * Worst case is O(log(n))</span>
<span class="comment">	 * </span><span class="type">@throws</span><span class="comment"> java.lang.ArithmeticException if there are more than 2^63-1 elements in the queue</span>
<span class="comment">	 * </span><span class="type">@return</span><span class="comment"> the number of elements on the priority queue</span>
<span class="comment">	 */</span>
<span class="normal">	</span><span class="keyword">public</span><span class="normal"> </span><span class="type">int</span><span class="normal"> </span><span class="function">size</span><span class="symbol">()</span><span class="normal"> </span><span class="cbracket">{</span>
<span class="normal">		</span><span class="type">int</span><span class="normal"> result </span><span class="symbol">=</span><span class="normal"> </span><span class="number">0</span><span class="symbol">,</span><span class="normal"> tmp</span><span class="symbol">;</span>
<span class="normal">		</span><span class="keyword">for</span><span class="normal"> </span><span class="symbol">(</span><span class="usertype">Node</span><span class="normal"> node </span><span class="symbol">=</span><span class="normal"> head</span><span class="symbol">;</span><span class="normal"> node </span><span class="symbol">!=</span><span class="normal"> </span><span class="keyword">null</span><span class="symbol">;</span><span class="normal"> node </span><span class="symbol">=</span><span class="normal"> node</span><span class="symbol">.</span><span class="normal">sibling</span><span class="symbol">)</span><span class="normal"> </span><span class="cbracket">{</span>
<span class="normal">			</span><span class="keyword">if</span><span class="normal"> </span><span class="symbol">(</span><span class="normal">node</span><span class="symbol">.</span><span class="normal">order </span><span class="symbol">&gt;</span><span class="normal"> </span><span class="number">30</span><span class="symbol">)</span><span class="normal"> </span><span class="cbracket">{</span><span class="normal"> </span><span class="keyword">throw</span><span class="normal"> </span><span class="keyword">new</span><span class="normal"> </span><span class="function">ArithmeticException</span><span class="symbol">(</span><span class="string">"The number of elements cannot be evaluated, but the priority queue is still valid."</span><span class="symbol">);</span><span class="normal"> </span><span class="cbracket">}</span>
<span class="normal">			tmp </span><span class="symbol">=</span><span class="normal"> </span><span class="number">1</span><span class="normal"> </span><span class="symbol">&lt;&lt;</span><span class="normal"> node</span><span class="symbol">.</span><span class="normal">order</span><span class="symbol">;</span>
<span class="normal">			result </span><span class="symbol">|=</span><span class="normal"> tmp</span><span class="symbol">;</span>
<span class="normal">		</span><span class="cbracket">}</span>
<span class="normal">		</span><span class="keyword">return</span><span class="normal"> result</span><span class="symbol">;</span>
<span class="normal">	</span><span class="cbracket">}</span>

<span class="normal">	</span><span class="comment">/**</span>
<span class="comment">	 * Puts a Key in the heap</span>
<span class="comment">	 * Worst case is O(log(n))</span>
<span class="comment">	 * </span><span class="type">@param</span><span class="comment"> key a Key</span>
<span class="comment">	 */</span>
<span class="normal">	</span><span class="keyword">public</span><span class="normal"> </span><span class="type">void</span><span class="normal"> </span><span class="function">insert</span><span class="symbol">(</span><span class="usertype">Key</span><span class="normal"> key</span><span class="symbol">)</span><span class="normal"> </span><span class="cbracket">{</span>
<span class="normal">		</span><span class="usertype">Node</span><span class="normal"> x </span><span class="symbol">=</span><span class="normal"> </span><span class="keyword">new</span><span class="normal"> </span><span class="function">Node</span><span class="symbol">();</span>
<span class="normal">		x</span><span class="symbol">.</span><span class="normal">key </span><span class="symbol">=</span><span class="normal"> key</span><span class="symbol">;</span>
<span class="normal">		x</span><span class="symbol">.</span><span class="normal">order </span><span class="symbol">=</span><span class="normal"> </span><span class="number">0</span><span class="symbol">;</span>
<span class="normal">		</span><span class="usertype">BinomialMinPQ&lt;Key&gt;</span><span class="normal"> H </span><span class="symbol">=</span><span class="normal"> </span><span class="keyword">new</span><span class="normal"> BinomialMinPQ</span><span class="symbol">&lt;</span><span class="normal">Key</span><span class="symbol">&gt;();</span><span class="normal"> </span><span class="comment">//The Comparator oh the H heap is not used</span>
<span class="normal">		H</span><span class="symbol">.</span><span class="normal">head </span><span class="symbol">=</span><span class="normal"> x</span><span class="symbol">;</span>
<span class="normal">		</span><span class="keyword">this</span><span class="symbol">.</span><span class="normal">head </span><span class="symbol">=</span><span class="normal"> </span><span class="keyword">this</span><span class="symbol">.</span><span class="function">union</span><span class="symbol">(</span><span class="normal">H</span><span class="symbol">).</span><span class="normal">head</span><span class="symbol">;</span>
<span class="normal">	</span><span class="cbracket">}</span>

<span class="normal">	</span><span class="comment">/**</span>
<span class="comment">	 * Get the minimum key currently in the queue</span>
<span class="comment">	 * Worst case is O(log(n))</span>
<span class="comment">	 * </span><span class="type">@throws</span><span class="comment"> java.util.NoSuchElementException if the priority queue is empty</span>
<span class="comment">	 * </span><span class="type">@return</span><span class="comment"> the minimum key currently in the priority queue</span>
<span class="comment">	 */</span>
<span class="normal">	</span><span class="keyword">public</span><span class="normal"> </span><span class="usertype">Key</span><span class="normal"> </span><span class="function">minKey</span><span class="symbol">()</span><span class="normal"> </span><span class="cbracket">{</span>
<span class="normal">		</span><span class="keyword">if</span><span class="normal"> </span><span class="symbol">(</span><span class="function">isEmpty</span><span class="symbol">())</span><span class="normal"> </span><span class="keyword">throw</span><span class="normal"> </span><span class="keyword">new</span><span class="normal"> </span><span class="function">NoSuchElementException</span><span class="symbol">(</span><span class="string">"Priority queue is empty"</span><span class="symbol">);</span>
<span class="normal">		</span><span class="usertype">Node</span><span class="normal"> min </span><span class="symbol">=</span><span class="normal"> head</span><span class="symbol">;</span>
<span class="normal">		</span><span class="usertype">Node</span><span class="normal"> current </span><span class="symbol">=</span><span class="normal"> head</span><span class="symbol">;</span>
<span class="normal">		</span><span class="keyword">while</span><span class="normal"> </span><span class="symbol">(</span><span class="normal">current</span><span class="symbol">.</span><span class="normal">sibling </span><span class="symbol">!=</span><span class="normal"> </span><span class="keyword">null</span><span class="symbol">)</span><span class="normal"> </span><span class="cbracket">{</span>
<span class="normal">			min </span><span class="symbol">=</span><span class="normal"> </span><span class="symbol">(</span><span class="function">greater</span><span class="symbol">(</span><span class="normal">min</span><span class="symbol">.</span><span class="normal">key</span><span class="symbol">,</span><span class="normal"> current</span><span class="symbol">.</span><span class="normal">sibling</span><span class="symbol">.</span><span class="normal">key</span><span class="symbol">))</span><span class="normal"> </span><span class="symbol">?</span><span class="normal"> current </span><span class="symbol">:</span><span class="normal"> min</span><span class="symbol">;</span>
<span class="normal">			current </span><span class="symbol">=</span><span class="normal"> current</span><span class="symbol">.</span><span class="normal">sibling</span><span class="symbol">;</span>
<span class="normal">		</span><span class="cbracket">}</span>
<span class="normal">		</span><span class="keyword">return</span><span class="normal"> min</span><span class="symbol">.</span><span class="normal">key</span><span class="symbol">;</span>
<span class="normal">	</span><span class="cbracket">}</span>

<span class="normal">	</span><span class="comment">/**</span>
<span class="comment">	 * Deletes the minimum key</span>
<span class="comment">	 * Worst case is O(log(n))</span>
<span class="comment">	 * </span><span class="type">@throws</span><span class="comment"> java.util.NoSuchElementException if the priority queue is empty</span>
<span class="comment">	 * </span><span class="type">@return</span><span class="comment"> the minimum key</span>
<span class="comment">	 */</span>
<span class="normal">	</span><span class="keyword">public</span><span class="normal"> </span><span class="usertype">Key</span><span class="normal"> </span><span class="function">delMin</span><span class="symbol">()</span><span class="normal"> </span><span class="cbracket">{</span>
<span class="normal">		</span><span class="keyword">if</span><span class="symbol">(</span><span class="function">isEmpty</span><span class="symbol">())</span><span class="normal"> </span><span class="keyword">throw</span><span class="normal"> </span><span class="keyword">new</span><span class="normal"> </span><span class="function">NoSuchElementException</span><span class="symbol">(</span><span class="string">"Priority queue is empty"</span><span class="symbol">);</span>
<span class="normal">		</span><span class="usertype">Node</span><span class="normal"> min </span><span class="symbol">=</span><span class="normal"> </span><span class="function">eraseMin</span><span class="symbol">();</span>
<span class="normal">		</span><span class="usertype">Node</span><span class="normal"> x </span><span class="symbol">=</span><span class="normal"> </span><span class="symbol">(</span><span class="normal">min</span><span class="symbol">.</span><span class="normal">child </span><span class="symbol">==</span><span class="normal"> </span><span class="keyword">null</span><span class="symbol">)</span><span class="normal"> </span><span class="symbol">?</span><span class="normal"> min </span><span class="symbol">:</span><span class="normal"> min</span><span class="symbol">.</span><span class="normal">child</span><span class="symbol">;</span>
<span class="normal">		</span><span class="keyword">if</span><span class="normal"> </span><span class="symbol">(</span><span class="normal">min</span><span class="symbol">.</span><span class="normal">child </span><span class="symbol">!=</span><span class="normal"> </span><span class="keyword">null</span><span class="symbol">)</span><span class="normal"> </span><span class="cbracket">{</span>
<span class="normal">			min</span><span class="symbol">.</span><span class="normal">child </span><span class="symbol">=</span><span class="normal"> </span><span class="keyword">null</span><span class="symbol">;</span>
<span class="normal">			</span><span class="usertype">Node</span><span class="normal"> prevx </span><span class="symbol">=</span><span class="normal"> </span><span class="keyword">null</span><span class="symbol">,</span><span class="normal"> nextx </span><span class="symbol">=</span><span class="normal"> x</span><span class="symbol">.</span><span class="normal">sibling</span><span class="symbol">;</span>
<span class="normal">			</span><span class="keyword">while</span><span class="normal"> </span><span class="symbol">(</span><span class="normal">nextx </span><span class="symbol">!=</span><span class="normal"> </span><span class="keyword">null</span><span class="symbol">)</span><span class="normal"> </span><span class="cbracket">{</span>
<span class="normal">				x</span><span class="symbol">.</span><span class="normal">sibling </span><span class="symbol">=</span><span class="normal"> prevx</span><span class="symbol">;</span>
<span class="normal">				prevx </span><span class="symbol">=</span><span class="normal"> x</span><span class="symbol">;</span>
<span class="normal">				x </span><span class="symbol">=</span><span class="normal"> nextx</span><span class="symbol">;</span><span class="normal">nextx </span><span class="symbol">=</span><span class="normal"> nextx</span><span class="symbol">.</span><span class="normal">sibling</span><span class="symbol">;</span>
<span class="normal">			</span><span class="cbracket">}</span>
<span class="normal">			x</span><span class="symbol">.</span><span class="normal">sibling </span><span class="symbol">=</span><span class="normal"> prevx</span><span class="symbol">;</span>
<span class="normal">			</span><span class="usertype">BinomialMinPQ&lt;Key&gt;</span><span class="normal"> H </span><span class="symbol">=</span><span class="normal"> </span><span class="keyword">new</span><span class="normal"> BinomialMinPQ</span><span class="symbol">&lt;</span><span class="normal">Key</span><span class="symbol">&gt;();</span>
<span class="normal">			H</span><span class="symbol">.</span><span class="normal">head </span><span class="symbol">=</span><span class="normal"> x</span><span class="symbol">;</span>
<span class="normal">			head </span><span class="symbol">=</span><span class="normal"> </span><span class="function">union</span><span class="symbol">(</span><span class="normal">H</span><span class="symbol">).</span><span class="normal">head</span><span class="symbol">;</span>
<span class="normal">		</span><span class="cbracket">}</span>
<span class="normal">		</span><span class="keyword">return</span><span class="normal"> min</span><span class="symbol">.</span><span class="normal">key</span><span class="symbol">;</span>
<span class="normal">	</span><span class="cbracket">}</span>
<span class="normal">	</span>
<span class="normal">	</span><span class="comment">/**</span>
<span class="comment">	 * Merges two Binomial heaps together</span>
<span class="comment">	 * This operation is destructive</span>
<span class="comment">	 * Worst case is O(log(n))</span>
<span class="comment">	 * </span><span class="type">@param</span><span class="comment"> heap a Binomial Heap to be merged with the current heap</span>
<span class="comment">	 * </span><span class="type">@throws</span><span class="comment"> java.util.IllegalArgumentException if the heap in parameter is null</span>
<span class="comment">	 * </span><span class="type">@return</span><span class="comment"> the union of two heaps</span>
<span class="comment">	 */</span>
<span class="normal">	</span><span class="keyword">public</span><span class="normal"> </span><span class="usertype">BinomialMinPQ&lt;Key&gt; union(BinomialMinPQ&lt;Key&gt;</span><span class="normal"> heap</span><span class="symbol">)</span><span class="normal"> </span><span class="cbracket">{</span>
<span class="normal">		</span><span class="keyword">if</span><span class="normal"> </span><span class="symbol">(</span><span class="normal">heap </span><span class="symbol">==</span><span class="normal"> </span><span class="keyword">null</span><span class="symbol">)</span><span class="normal"> </span><span class="keyword">throw</span><span class="normal"> </span><span class="keyword">new</span><span class="normal"> </span><span class="function">IllegalArgumentException</span><span class="symbol">(</span><span class="string">"Cannot merge a Binomial Heap with null"</span><span class="symbol">);</span>
<span class="normal">		</span><span class="keyword">this</span><span class="symbol">.</span><span class="normal">head </span><span class="symbol">=</span><span class="normal"> </span><span class="function">merge</span><span class="symbol">(</span><span class="keyword">new</span><span class="normal"> </span><span class="function">Node</span><span class="symbol">(),</span><span class="normal"> </span><span class="keyword">this</span><span class="symbol">.</span><span class="normal">head</span><span class="symbol">,</span><span class="normal"> heap</span><span class="symbol">.</span><span class="normal">head</span><span class="symbol">).</span><span class="normal">sibling</span><span class="symbol">;</span>
<span class="normal">		</span><span class="usertype">Node</span><span class="normal"> x </span><span class="symbol">=</span><span class="normal"> </span><span class="keyword">this</span><span class="symbol">.</span><span class="normal">head</span><span class="symbol">;</span>
<span class="normal">		</span><span class="usertype">Node</span><span class="normal"> prevx </span><span class="symbol">=</span><span class="normal"> </span><span class="keyword">null</span><span class="symbol">,</span><span class="normal"> nextx </span><span class="symbol">=</span><span class="normal"> x</span><span class="symbol">.</span><span class="normal">sibling</span><span class="symbol">;</span>
<span class="normal">		</span><span class="keyword">while</span><span class="normal"> </span><span class="symbol">(</span><span class="normal">nextx </span><span class="symbol">!=</span><span class="normal"> </span><span class="keyword">null</span><span class="symbol">)</span><span class="normal"> </span><span class="cbracket">{</span>
<span class="normal">			</span><span class="keyword">if</span><span class="normal"> </span><span class="symbol">(</span><span class="normal">x</span><span class="symbol">.</span><span class="normal">order </span><span class="symbol">&lt;</span><span class="normal"> nextx</span><span class="symbol">.</span><span class="normal">order </span><span class="symbol">||</span>
<span class="normal">			   </span><span class="symbol">(</span><span class="normal">nextx</span><span class="symbol">.</span><span class="normal">sibling </span><span class="symbol">!=</span><span class="normal"> </span><span class="keyword">null</span><span class="normal"> </span><span class="symbol">&amp;&amp;</span><span class="normal"> nextx</span><span class="symbol">.</span><span class="normal">sibling</span><span class="symbol">.</span><span class="normal">order </span><span class="symbol">==</span><span class="normal"> x</span><span class="symbol">.</span><span class="normal">order</span><span class="symbol">))</span><span class="normal"> </span><span class="cbracket">{</span>
<span class="normal">				prevx </span><span class="symbol">=</span><span class="normal"> x</span><span class="symbol">;</span><span class="normal"> x </span><span class="symbol">=</span><span class="normal"> nextx</span><span class="symbol">;</span>
<span class="normal">			</span><span class="cbracket">}</span><span class="normal"> </span><span class="keyword">else</span><span class="normal"> </span><span class="keyword">if</span><span class="normal"> </span><span class="symbol">(</span><span class="function">greater</span><span class="symbol">(</span><span class="normal">nextx</span><span class="symbol">.</span><span class="normal">key</span><span class="symbol">,</span><span class="normal"> x</span><span class="symbol">.</span><span class="normal">key</span><span class="symbol">))</span><span class="normal"> </span><span class="cbracket">{</span>
<span class="normal">				x</span><span class="symbol">.</span><span class="normal">sibling </span><span class="symbol">=</span><span class="normal"> nextx</span><span class="symbol">.</span><span class="normal">sibling</span><span class="symbol">;</span>
<span class="normal">				</span><span class="function">link</span><span class="symbol">(</span><span class="normal">nextx</span><span class="symbol">,</span><span class="normal"> x</span><span class="symbol">);</span>
<span class="normal">			</span><span class="cbracket">}</span><span class="normal"> </span><span class="keyword">else</span><span class="normal"> </span><span class="cbracket">{</span>
<span class="normal">				</span><span class="keyword">if</span><span class="normal"> </span><span class="symbol">(</span><span class="normal">prevx </span><span class="symbol">==</span><span class="normal"> </span><span class="keyword">null</span><span class="symbol">)</span><span class="normal"> </span><span class="cbracket">{</span><span class="normal"> </span><span class="keyword">this</span><span class="symbol">.</span><span class="normal">head </span><span class="symbol">=</span><span class="normal"> nextx</span><span class="symbol">;</span><span class="normal"> </span><span class="cbracket">}</span>
<span class="normal">				</span><span class="keyword">else</span><span class="normal"> </span><span class="cbracket">{</span><span class="normal"> prevx</span><span class="symbol">.</span><span class="normal">sibling </span><span class="symbol">=</span><span class="normal"> nextx</span><span class="symbol">;</span><span class="normal"> </span><span class="cbracket">}</span>
<span class="normal">				</span><span class="function">link</span><span class="symbol">(</span><span class="normal">x</span><span class="symbol">,</span><span class="normal"> nextx</span><span class="symbol">);</span>
<span class="normal">				x </span><span class="symbol">=</span><span class="normal"> nextx</span><span class="symbol">;</span>
<span class="normal">			</span><span class="cbracket">}</span>
<span class="normal">			nextx </span><span class="symbol">=</span><span class="normal"> x</span><span class="symbol">.</span><span class="normal">sibling</span><span class="symbol">;</span>
<span class="normal">		</span><span class="cbracket">}</span>
<span class="normal">		</span><span class="keyword">return</span><span class="normal"> </span><span class="keyword">this</span><span class="symbol">;</span>
<span class="normal">	</span><span class="cbracket">}</span>
<span class="normal">	</span>
<span class="normal">	</span><span class="comment">/*************************************************</span>
<span class="comment">	 * General helper functions</span>
<span class="comment">	 ************************************************/</span>
<span class="normal">	</span>
<span class="normal">	</span><span class="comment">//Compares two keys</span>
<span class="normal">	</span><span class="keyword">private</span><span class="normal"> </span><span class="type">boolean</span><span class="normal"> </span><span class="function">greater</span><span class="symbol">(</span><span class="usertype">Key</span><span class="normal"> n</span><span class="symbol">,</span><span class="normal"> </span><span class="usertype">Key</span><span class="normal"> m</span><span class="symbol">)</span><span class="normal"> </span><span class="cbracket">{</span>
<span class="normal">		</span><span class="keyword">if</span><span class="normal"> </span><span class="symbol">(</span><span class="normal">n </span><span class="symbol">==</span><span class="normal"> </span><span class="keyword">null</span><span class="symbol">)</span><span class="normal"> </span><span class="keyword">return</span><span class="normal"> </span><span class="keyword">false</span><span class="symbol">;</span>
<span class="normal">		</span><span class="keyword">if</span><span class="normal"> </span><span class="symbol">(</span><span class="normal">m </span><span class="symbol">==</span><span class="normal"> </span><span class="keyword">null</span><span class="symbol">)</span><span class="normal"> </span><span class="keyword">return</span><span class="normal"> </span><span class="keyword">true</span><span class="symbol">;</span>
<span class="normal">		</span><span class="keyword">return</span><span class="normal"> comp</span><span class="symbol">.</span><span class="function">compare</span><span class="symbol">(</span><span class="normal">n</span><span class="symbol">,</span><span class="normal"> m</span><span class="symbol">)</span><span class="normal"> </span><span class="symbol">&gt;</span><span class="normal"> </span><span class="number">0</span><span class="symbol">;</span>
<span class="normal">	</span><span class="cbracket">}</span>
<span class="normal">	</span>
<span class="normal">	</span><span class="comment">//Assuming root1 holds a greater key than root2, root2 becomes the new root</span>
<span class="normal">	</span><span class="keyword">private</span><span class="normal"> </span><span class="type">void</span><span class="normal"> </span><span class="function">link</span><span class="symbol">(</span><span class="usertype">Node</span><span class="normal"> root1</span><span class="symbol">,</span><span class="normal"> </span><span class="usertype">Node</span><span class="normal"> root2</span><span class="symbol">)</span><span class="normal"> </span><span class="cbracket">{</span>
<span class="normal">		root1</span><span class="symbol">.</span><span class="normal">sibling </span><span class="symbol">=</span><span class="normal"> root2</span><span class="symbol">.</span><span class="normal">child</span><span class="symbol">;</span>
<span class="normal">		root2</span><span class="symbol">.</span><span class="normal">child </span><span class="symbol">=</span><span class="normal"> root1</span><span class="symbol">;</span>
<span class="normal">		root2</span><span class="symbol">.</span><span class="normal">order</span><span class="symbol">++;</span>
<span class="normal">	</span><span class="cbracket">}</span>
<span class="normal">	</span>
<span class="normal">	</span><span class="comment">//Deletes and return the node containing the minimum key</span>
<span class="normal">	</span><span class="keyword">private</span><span class="normal"> </span><span class="usertype">Node</span><span class="normal"> </span><span class="function">eraseMin</span><span class="symbol">()</span><span class="normal"> </span><span class="cbracket">{</span>
<span class="normal">		</span><span class="usertype">Node</span><span class="normal"> min </span><span class="symbol">=</span><span class="normal"> head</span><span class="symbol">;</span>
<span class="normal">		</span><span class="usertype">Node</span><span class="normal"> previous </span><span class="symbol">=</span><span class="normal"> </span><span class="keyword">new</span><span class="normal"> </span><span class="function">Node</span><span class="symbol">();</span>
<span class="normal">		</span><span class="usertype">Node</span><span class="normal"> current </span><span class="symbol">=</span><span class="normal"> head</span><span class="symbol">;</span>
<span class="normal">		</span><span class="keyword">while</span><span class="normal"> </span><span class="symbol">(</span><span class="normal">current</span><span class="symbol">.</span><span class="normal">sibling </span><span class="symbol">!=</span><span class="normal"> </span><span class="keyword">null</span><span class="symbol">)</span><span class="normal"> </span><span class="cbracket">{</span>
<span class="normal">			</span><span class="keyword">if</span><span class="normal"> </span><span class="symbol">(</span><span class="function">greater</span><span class="symbol">(</span><span class="normal">min</span><span class="symbol">.</span><span class="normal">key</span><span class="symbol">,</span><span class="normal"> current</span><span class="symbol">.</span><span class="normal">sibling</span><span class="symbol">.</span><span class="normal">key</span><span class="symbol">))</span><span class="normal"> </span><span class="cbracket">{</span>
<span class="normal">				previous </span><span class="symbol">=</span><span class="normal"> current</span><span class="symbol">;</span>
<span class="normal">				min </span><span class="symbol">=</span><span class="normal"> current</span><span class="symbol">.</span><span class="normal">sibling</span><span class="symbol">;</span>
<span class="normal">			</span><span class="cbracket">}</span>
<span class="normal">			current </span><span class="symbol">=</span><span class="normal"> current</span><span class="symbol">.</span><span class="normal">sibling</span><span class="symbol">;</span>
<span class="normal">		</span><span class="cbracket">}</span>
<span class="normal">		previous</span><span class="symbol">.</span><span class="normal">sibling </span><span class="symbol">=</span><span class="normal"> min</span><span class="symbol">.</span><span class="normal">sibling</span><span class="symbol">;</span>
<span class="normal">		</span><span class="keyword">if</span><span class="normal"> </span><span class="symbol">(</span><span class="normal">min </span><span class="symbol">==</span><span class="normal"> head</span><span class="symbol">)</span><span class="normal"> head </span><span class="symbol">=</span><span class="normal"> min</span><span class="symbol">.</span><span class="normal">sibling</span><span class="symbol">;</span>
<span class="normal">		</span><span class="keyword">return</span><span class="normal"> min</span><span class="symbol">;</span>
<span class="normal">	</span><span class="cbracket">}</span>
<span class="normal">	</span>
<span class="normal">	</span><span class="comment">/**************************************************</span>
<span class="comment">	 * Functions for inserting a key in the heap</span>
<span class="comment">	 *************************************************/</span>
<span class="normal">	</span>
<span class="normal">	</span><span class="comment">//Merges two root lists into one, there can be up to 2 Binomial Trees of same order</span>
<span class="normal">	</span><span class="keyword">private</span><span class="normal"> </span><span class="usertype">Node</span><span class="normal"> </span><span class="function">merge</span><span class="symbol">(</span><span class="usertype">Node</span><span class="normal"> h</span><span class="symbol">,</span><span class="normal"> </span><span class="usertype">Node</span><span class="normal"> x</span><span class="symbol">,</span><span class="normal"> </span><span class="usertype">Node</span><span class="normal"> y</span><span class="symbol">)</span><span class="normal"> </span><span class="cbracket">{</span>
<span class="normal">		</span><span class="keyword">if</span><span class="normal"> </span><span class="symbol">(</span><span class="normal">x </span><span class="symbol">==</span><span class="normal"> </span><span class="keyword">null</span><span class="normal"> </span><span class="symbol">&amp;&amp;</span><span class="normal"> y </span><span class="symbol">==</span><span class="normal"> </span><span class="keyword">null</span><span class="symbol">)</span><span class="normal"> </span><span class="keyword">return</span><span class="normal"> h</span><span class="symbol">;</span>
<span class="normal">		</span><span class="keyword">else</span><span class="normal"> </span><span class="keyword">if</span><span class="normal"> </span><span class="symbol">(</span><span class="normal">x </span><span class="symbol">==</span><span class="normal"> </span><span class="keyword">null</span><span class="symbol">)</span><span class="normal">  		h</span><span class="symbol">.</span><span class="normal">sibling </span><span class="symbol">=</span><span class="normal"> </span><span class="function">merge</span><span class="symbol">(</span><span class="normal">y</span><span class="symbol">,</span><span class="normal"> x</span><span class="symbol">,</span><span class="normal"> y</span><span class="symbol">.</span><span class="normal">sibling</span><span class="symbol">);</span>
<span class="normal">		</span><span class="keyword">else</span><span class="normal"> </span><span class="keyword">if</span><span class="normal"> </span><span class="symbol">(</span><span class="normal">y </span><span class="symbol">==</span><span class="normal"> </span><span class="keyword">null</span><span class="symbol">)</span><span class="normal"> 		h</span><span class="symbol">.</span><span class="normal">sibling </span><span class="symbol">=</span><span class="normal"> </span><span class="function">merge</span><span class="symbol">(</span><span class="normal">x</span><span class="symbol">,</span><span class="normal"> x</span><span class="symbol">.</span><span class="normal">sibling</span><span class="symbol">,</span><span class="normal"> y</span><span class="symbol">);</span>
<span class="normal">		</span><span class="keyword">else</span><span class="normal"> </span><span class="keyword">if</span><span class="normal"> </span><span class="symbol">(</span><span class="normal">x</span><span class="symbol">.</span><span class="normal">order </span><span class="symbol">&lt;</span><span class="normal"> y</span><span class="symbol">.</span><span class="normal">order</span><span class="symbol">)</span><span class="normal"> h</span><span class="symbol">.</span><span class="normal">sibling </span><span class="symbol">=</span><span class="normal"> </span><span class="function">merge</span><span class="symbol">(</span><span class="normal">x</span><span class="symbol">,</span><span class="normal"> x</span><span class="symbol">.</span><span class="normal">sibling</span><span class="symbol">,</span><span class="normal"> y</span><span class="symbol">);</span>
<span class="normal">		</span><span class="keyword">else</span><span class="normal"> 						h</span><span class="symbol">.</span><span class="normal">sibling </span><span class="symbol">=</span><span class="normal"> </span><span class="function">merge</span><span class="symbol">(</span><span class="normal">y</span><span class="symbol">,</span><span class="normal"> x</span><span class="symbol">,</span><span class="normal"> y</span><span class="symbol">.</span><span class="normal">sibling</span><span class="symbol">);</span>
<span class="normal">		</span><span class="keyword">return</span><span class="normal"> h</span><span class="symbol">;</span>
<span class="normal">	</span><span class="cbracket">}</span>
<span class="normal">	</span>
<span class="normal">	</span><span class="comment">/******************************************************************</span>
<span class="comment">	 * Iterator</span>
<span class="comment">	 *****************************************************************/</span>
<span class="normal">	</span>
<span class="normal">	</span><span class="comment">/**</span>
<span class="comment">	 * Gets an Iterator over the keys in the priority queue in ascending order</span>
<span class="comment">	 * The Iterator does not implement the remove() method</span>
<span class="comment">	 * iterator() : Worst case is O(n)</span>
<span class="comment">	 * next() : 	Worst case is O(log(n))</span>
<span class="comment">	 * hasNext() : 	Worst case is O(1)</span>
<span class="comment">	 * </span><span class="type">@return</span><span class="comment"> an Iterator over the keys in the priority queue in ascending order</span>
<span class="comment">	 */</span>
<span class="normal">	</span><span class="keyword">public</span><span class="normal"> </span><span class="usertype">Iterator&lt;Key&gt;</span><span class="normal"> </span><span class="function">iterator</span><span class="symbol">()</span><span class="normal"> </span><span class="cbracket">{</span>
<span class="normal">		</span><span class="keyword">return</span><span class="normal"> </span><span class="keyword">new</span><span class="normal"> </span><span class="function">MyIterator</span><span class="symbol">();</span>
<span class="normal">	</span><span class="cbracket">}</span>
<span class="normal">	</span>
<span class="normal">	</span><span class="keyword">private</span><span class="normal"> </span><span class="keyword">class</span><span class="normal"> </span><span class="classname">MyIterator</span><span class="normal"> </span><span class="keyword">implements</span><span class="normal"> Iterator</span><span class="symbol">&lt;</span><span class="normal">Key</span><span class="symbol">&gt;</span><span class="normal"> </span><span class="cbracket">{</span>
<span class="normal">		</span><span class="usertype">BinomialMinPQ&lt;Key&gt;</span><span class="normal"> data</span><span class="symbol">;</span>
<span class="normal">		</span>
<span class="normal">		</span><span class="comment">//Constructor clones recursively the elements in the queue</span>
<span class="normal">		</span><span class="comment">//It takes linear time</span>
<span class="normal">		</span><span class="keyword">public</span><span class="normal"> </span><span class="function">MyIterator</span><span class="symbol">()</span><span class="normal"> </span><span class="cbracket">{</span>
<span class="normal">			data </span><span class="symbol">=</span><span class="normal"> </span><span class="keyword">new</span><span class="normal"> BinomialMinPQ</span><span class="symbol">&lt;</span><span class="normal">Key</span><span class="symbol">&gt;(</span><span class="normal">comp</span><span class="symbol">);</span>
<span class="normal">			data</span><span class="symbol">.</span><span class="normal">head </span><span class="symbol">=</span><span class="normal"> </span><span class="function">clone</span><span class="symbol">(</span><span class="normal">head</span><span class="symbol">,</span><span class="normal"> </span><span class="keyword">false</span><span class="symbol">,</span><span class="normal"> </span><span class="keyword">false</span><span class="symbol">,</span><span class="normal"> </span><span class="keyword">null</span><span class="symbol">);</span>
<span class="normal">		</span><span class="cbracket">}</span>
<span class="normal">		</span>
<span class="normal">		</span><span class="keyword">private</span><span class="normal"> </span><span class="usertype">Node</span><span class="normal"> </span><span class="function">clone</span><span class="symbol">(</span><span class="usertype">Node</span><span class="normal"> x</span><span class="symbol">,</span><span class="normal"> </span><span class="type">boolean</span><span class="normal"> isParent</span><span class="symbol">,</span><span class="normal"> </span><span class="type">boolean</span><span class="normal"> isChild</span><span class="symbol">,</span><span class="normal"> </span><span class="usertype">Node</span><span class="normal"> parent</span><span class="symbol">)</span><span class="normal"> </span><span class="cbracket">{</span>
<span class="normal">			</span><span class="keyword">if</span><span class="normal"> </span><span class="symbol">(</span><span class="normal">x </span><span class="symbol">==</span><span class="normal"> </span><span class="keyword">null</span><span class="symbol">)</span><span class="normal"> </span><span class="keyword">return</span><span class="normal"> </span><span class="keyword">null</span><span class="symbol">;</span>
<span class="normal">			</span><span class="usertype">Node</span><span class="normal"> node </span><span class="symbol">=</span><span class="normal"> </span><span class="keyword">new</span><span class="normal"> </span><span class="function">Node</span><span class="symbol">();</span>
<span class="normal">			node</span><span class="symbol">.</span><span class="normal">key </span><span class="symbol">=</span><span class="normal"> x</span><span class="symbol">.</span><span class="normal">key</span><span class="symbol">;</span>
<span class="normal">			node</span><span class="symbol">.</span><span class="normal">sibling </span><span class="symbol">=</span><span class="normal"> </span><span class="function">clone</span><span class="symbol">(</span><span class="normal">x</span><span class="symbol">.</span><span class="normal">sibling</span><span class="symbol">,</span><span class="normal"> </span><span class="keyword">false</span><span class="symbol">,</span><span class="normal"> </span><span class="keyword">false</span><span class="symbol">,</span><span class="normal"> parent</span><span class="symbol">);</span>
<span class="normal">			node</span><span class="symbol">.</span><span class="normal">child </span><span class="symbol">=</span><span class="normal"> </span><span class="function">clone</span><span class="symbol">(</span><span class="normal">x</span><span class="symbol">.</span><span class="normal">child</span><span class="symbol">,</span><span class="normal"> </span><span class="keyword">false</span><span class="symbol">,</span><span class="normal"> </span><span class="keyword">true</span><span class="symbol">,</span><span class="normal"> node</span><span class="symbol">);</span>
<span class="normal">			</span><span class="keyword">return</span><span class="normal"> node</span><span class="symbol">;</span>
<span class="normal">		</span><span class="cbracket">}</span>
<span class="normal">		</span>
<span class="normal">		</span><span class="keyword">public</span><span class="normal"> </span><span class="type">boolean</span><span class="normal"> </span><span class="function">hasNext</span><span class="symbol">()</span><span class="normal"> </span><span class="cbracket">{</span>
<span class="normal">			</span><span class="keyword">return</span><span class="normal"> </span><span class="symbol">!</span><span class="normal">data</span><span class="symbol">.</span><span class="function">isEmpty</span><span class="symbol">();</span>
<span class="normal">		</span><span class="cbracket">}</span>
<span class="normal">		</span>
<span class="normal">		</span><span class="keyword">public</span><span class="normal"> </span><span class="usertype">Key</span><span class="normal"> </span><span class="function">next</span><span class="symbol">()</span><span class="normal"> </span><span class="cbracket">{</span>
<span class="normal">			</span><span class="keyword">return</span><span class="normal"> data</span><span class="symbol">.</span><span class="function">delMin</span><span class="symbol">();</span>
<span class="normal">		</span><span class="cbracket">}</span>
<span class="normal">		</span>
<span class="normal">		</span><span class="keyword">public</span><span class="normal"> </span><span class="type">void</span><span class="normal"> </span><span class="function">remove</span><span class="symbol">()</span><span class="normal"> </span><span class="cbracket">{</span>
<span class="normal">			</span><span class="keyword">throw</span><span class="normal"> </span><span class="keyword">new</span><span class="normal"> </span><span class="function">UnsupportedOperationException</span><span class="symbol">();</span>
<span class="normal">		</span><span class="cbracket">}</span>
<span class="normal">	</span><span class="cbracket">}</span>
<span class="normal">	</span>
<span class="normal">	</span><span class="comment">/***************************</span>
<span class="comment">	 * Comparator</span>
<span class="comment">	 **************************/</span>
<span class="normal">	</span>
<span class="normal">	</span><span class="comment">//default Comparator</span>
<span class="normal">	</span><span class="keyword">private</span><span class="normal"> </span><span class="keyword">class</span><span class="normal"> </span><span class="classname">MyComparator</span><span class="normal"> </span><span class="keyword">implements</span><span class="normal"> Comparator</span><span class="symbol">&lt;</span><span class="normal">Key</span><span class="symbol">&gt;</span><span class="normal"> </span><span class="cbracket">{</span>
<span class="normal">		@Override</span>
<span class="normal">		</span><span class="keyword">public</span><span class="normal"> </span><span class="type">int</span><span class="normal"> </span><span class="function">compare</span><span class="symbol">(</span><span class="usertype">Key</span><span class="normal"> key1</span><span class="symbol">,</span><span class="normal"> </span><span class="usertype">Key</span><span class="normal"> key2</span><span class="symbol">)</span><span class="normal"> </span><span class="cbracket">{</span>
<span class="normal">			</span><span class="keyword">return</span><span class="normal"> </span><span class="symbol">((</span><span class="normal">Comparable</span><span class="symbol">&lt;</span><span class="normal">Key</span><span class="symbol">&gt;)</span><span class="normal"> key1</span><span class="symbol">).</span><span class="function">compareTo</span><span class="symbol">(</span><span class="normal">key2</span><span class="symbol">);</span>
<span class="normal">		</span><span class="cbracket">}</span>
<span class="normal">	</span><span class="cbracket">}</span>
<span class="normal">	</span>
<span class="cbracket">}</span>

<span class="comment">/******************************************************************************</span>
<span class="comment"> *  Copyright 2002-2015, Robert Sedgewick and Kevin Wayne.</span>
<span class="comment"> *</span>
<span class="comment"> *  This file is part of algs4.jar, which accompanies the textbook</span>
<span class="comment"> *</span>
<span class="comment"> *      Algorithms, 4th edition by Robert Sedgewick and Kevin Wayne,</span>
<span class="comment"> *      Addison-Wesley Professional, 2011, ISBN 0-321-57351-X.</span>
<span class="comment"> *      </span><span class="url">http://algs4.cs.princeton.edu</span>
<span class="comment"> *</span>
<span class="comment"> *</span>
<span class="comment"> *  algs4.jar is free software: you can redistribute it and/or modify</span>
<span class="comment"> *  it under the terms of the GNU General Public License as published by</span>
<span class="comment"> *  the Free Software Foundation, either version 3 of the License, or</span>
<span class="comment"> *  (at your option) any later version.</span>
<span class="comment"> *</span>
<span class="comment"> *  algs4.jar is distributed in the hope that it will be useful,</span>
<span class="comment"> *  but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
<span class="comment"> *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
<span class="comment"> *  GNU General Public License for more details.</span>
<span class="comment"> *</span>
<span class="comment"> *  You should have received a copy of the GNU General Public License</span>
<span class="comment"> *  along with algs4.jar.  If not, see </span><span class="url">http://www.gnu.org/licenses.</span>
<span class="comment"> ******************************************************************************/</span>
</tt></pre>

<script type="text/javascript">
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
</script>
<script type="text/javascript">
try {
var pageTracker = _gat._getTracker("UA-10811519-2");
pageTracker._trackPageview();
} catch(err) {}</script>

</body>

<p><br><address><small>
Last updated: Mon Mar 21 10:51:08 EDT 2016.
</small></address>

</html>
